﻿Imports DTO
Imports System.Data.SqlClient

Public Class TaiKhoan_DAO
    Public Shared Function LoadData() As List(Of TaiKhoan_DTO)
        Dim ds As New List(Of TaiKhoan_DTO)
        Dim dt As DataTable
        dt = DataProvider.loadDataTable("select *from TAIKHOAN")

        For Each row As DataRow In dt.Rows
            Dim tk As New TaiKhoan_DTO
            tk.maTK = row(0)
            tk.tenTK = row(1).ToString
            tk.matKhau = row(2).ToString
            tk.maTrangThai = row(3)
            tk.maLoaiTK = row(4)
            ds.Add(tk)
        Next

        Return ds
    End Function

    Public Shared Function getEmail() As DataTable
        Return DataProvider.loadDataWithStore("TaiKhoanGetEmail")
    End Function

    Public Shared Sub updateMatKhau(ByVal pass As String)
        Dim query As String = "update taikhoan set matkhau = '" + pass + "'"
        DataProvider.ExecuteNonQuery(query)
    End Sub

    'Public Shared Function getUserAndMK(ByVal user As String, ByVal pass As String) As DataTable
    '    Dim query As String = "select *from taikhoan where tentk = '" + user + "' and matkhau = '" + pass + "'"
    '    Return DataProvider.loadDataTable(query)
    'End Function

    Public Shared Function TaiKhoanGetAllInfo(ByVal tendn As String) As DataTable
        Dim dt As New DataTable
        Dim con As SqlConnection = DataProvider.ConnectToDB
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "TaiKhoanGetAllInfo"
        cmd.Connection = con

        Dim para As New SqlParameter("tentk", SqlDbType.NVarChar, 30)
        para.Direction = ParameterDirection.Input
        para.Value = tendn
        cmd.Parameters.Add(para)

        Dim adapter As New SqlDataAdapter(cmd)
        adapter.Fill(dt)
        con.Close()

        Return dt
    End Function

    Public Shared Function TaiKhoanGetInfo(ByVal tendn As String) As DataTable
        Dim dt As New DataTable
        Dim con As SqlConnection = DataProvider.ConnectToDB
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "TaiKhoanGetInfo"
        cmd.Connection = con

        Dim para As New SqlParameter("tentk", SqlDbType.NVarChar, 30)
        para.Direction = ParameterDirection.Input
        para.Value = tendn
        cmd.Parameters.Add(para)

        Dim adapter As New SqlDataAdapter(cmd)
        adapter.Fill(dt)
        con.Close()

        Return dt
    End Function

    'Kiem tra xem tai khoan dang ky co bi trung khong
    Public Shared Function KiemTraTaiKhoan(ByVal tentk As String) As DataTable
        Dim dt As New DataTable
        Dim con As SqlConnection = DataProvider.ConnectToDB
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "TaiKhoan_KiemTra_TenTK"
        cmd.Connection = con

        Dim para As New SqlParameter("tentk", SqlDbType.NVarChar, 30)
        para.Direction = ParameterDirection.Input
        para.Value = tentk
        cmd.Parameters.Add(para)

        Dim adapter As New SqlDataAdapter(cmd)
        adapter.Fill(dt)
        con.Close()

        Return dt
    End Function

End Class
